package com.lzy.liujing.restaurant.dao;

import com.lzy.liujing.restaurant.entity.Order;
import com.lzy.liujing.restaurant.entity.PageItem;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface OrderDao{

    @Select("select * from r_order")
    List<Order> selectAll();

    @Select("<script> SELECT * from r_order" +
            "<where>"+
            "<if test='deskCode != null'>and desk_code = #{deskCode}</if> "+
            " <if test='peopleNum != null'>and people_num = #{peopleNum}</if> "+
            " <if test='payStatus != null'>and pay_status = #{payStatus}</if> " +
            " <if test='createTime != null'>and create_time = #{createTime}</if> " +
            " <if test='orderCode != null'>and order_code = #{orderCode}</if> " +
            "</where>"+
            "</script>")
//    @Select("select * from r_order ")
    List<Order> findPage(Order query);

    @Delete("delete from r_order where order_id =#{orderId}")
    int delete(Integer id);

    @Insert("insert into r_order (order_code, desk_code,total_price,people_num,pay_status,finish_status,create_time ) values " +
            " (#{orderCode}, #{deskCode}, #{totalPrice},#{peopleNum},#{payStatus},#{finishStatus},#{createTime})")
    int insert(Order brand);

    @Update("update r_order set order_code = #{orderCode}, desk_code = #{deskCode}," +
            " total_price = #{totalPrice}, people_num = #{peopleNum}, pay_status = #{payStatus} where order_id = #{orderId}")
    int update(Order brand);

    @Select("SELECT * FROM r_order WHERE order_id = #{orderId}")
    Order getById(Integer id);

    @Update("UPDATE r_order SET pay_status = #{payStatus} WHERE order_id = #{orderId}")
    int updateBatch(@Param("orderId") Integer orderId, @Param("payStatus") String payStatus);

    @Update({
            "<script>",
            "UPDATE r_order",
            "SET total_price = #{totalPrice}",
            "WHERE order_code = #{orderCode}",
            "</script>"
    })
    int updateTotalPriceByOrderCode(@Param("orderCode") String orderCode, @Param("totalPrice") double totalPrice);

    @Update({
            "<script>",
            "UPDATE r_order",
            "SET finish_status = #{finishStatus}",
            "WHERE order_id = #{orderId}",
            "</script>"
    })
    int updateFinishByOrderCode(@Param("orderId") Integer orderId, @Param("finishStatus") String finishStatus);


}
